<?php
include('../../Connections/KRAPPERCON.php');
$oper = getVal('oper');
$alm = getVal('almacen');
$cod = getVal('codigo');

if ($oper == 'view'){

$filas = 0;

$sql = "call sp_ArtAlmCos(" . $alm . ",'" . $cod . "');";
$res = $mysqli->exeQuery($sql);

?>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="tableIn" rules="all">
    <thead>
      <tr>
      <th>Almacen</th>
        <th>Codigo</th>
        <th>Descripcion</th>
        <th>Precio Actual</th>
        <th>Costo Actual</th>
        <th>Nuevo Costo</th><th></th>
      </tr>
      </thead>
      <tbody>
<?php 
$filas = $mysqli->affected_rows;
if ($res){
	while($row = $res->fetch_assoc()){
?>
      <tr>
        <td class="clsCosAlm"><?php echo $row['AlmacenID']; ?></td>
        <td class="clsCosCod"><?php echo $row['ArticuloID']; ?></td>
        <td><?php echo $row['ArticuloName']; ?></td>
        <td class="qt"><?php echo $row['ArticuloPre']; ?></td>
        <td class="qt"><?php echo $row['ArtAlmCos']; ?></td>
        <td><input type="text" value="<?php echo $row['ArtAlmCos']; ?>" class="clsCosCos qt"/></td>
        <td align="center"><input type="button" value="Guardar" onClick="saveCosThis(this)"></td>
      </tr>
<?php 	
	}
$mysqli->check_result();
}

?>
      </tbody>
    </table>
<?php 
if ($filas > 1){
?>
<input type="button" value="Guardar" onClick="saveNewCos()">
<?php 
}
} //
elseif ($oper == 'save') {
$newcos = getVal('costo');
$in =getVal('indiv');
$sql = "call sp_updCostoAlm('".$user_now."',".$alm.",'".$cod."','".$newcos."');";
$add = '';
if ($in == 1)
$add = '';
else 
$add = "$('#d_cs_tbl').html('');";

$res = $mysqli->exeQuery($sql);
doEcho($sql);
if ($res){
	if ($row = $res->fetch_assoc()){
		if (trim($row['msgerr'])==''){
		echo ("<script type='text/javascript'>".$add."showOk('Se ha actualizado el Articulo ".$cod." en almacen ".$alm." a " .$newcos . "');</script>");
		}
		else {
		echo ("<script type='text/javascript'>showOk('".$alm." ".$cod." ".$row['msgerr']."');</script>");
		}
	}
$mysqli->check_result();
}
//$('#d_cs_tbl
}
?>